package main

import (
	"github.com/rpcxio/rpcx-etcd/serverplugin"
	"github.com/smallnest/rpcx/server"
	"h_rpcx/serve/workbench/basics"
	"h_rpcx/serve/workbench/business"
	"h_rpcx/serve/workbench/business/workbenchService"
	"log"
	"time"
)

func init() {
	err := basics.SettIng("Etcd", &basics.EtcdS)
	if err != nil {
		panic(err.Error())
	}
	err = basics.SettIng("Serve", &basics.ServeS)
	if err != nil {
		panic(err.Error())
	}
	err = basics.SettIng("Mysql", &basics.MysqlS)
	if err != nil {
		panic(err.Error())
	}
	business.NewServiceContext() //数据库库连接
}

func main() {
	s := server.NewServer()
	workbench := &serverplugin.EtcdV3RegisterPlugin{
		ServiceAddress: "tcp@localhost" + basics.ServeS.Port,
		EtcdServers:    []string{basics.EtcdS.Addr},
		BasePath:       basics.EtcdS.BasePath,
		UpdateInterval: time.Minute,
	}
	s.Plugins.Add(workbench)
	err := s.RegisterName(basics.ServeS.Name, workbenchService.NewWorkbenchService(), "")
	if err != nil {
		panic(err.Error())
	}
	log.Printf("当前启动的端口为%v,当前的服务名称：%v,当前的服务路径：%v", basics.ServeS.Port, basics.ServeS.Name, basics.EtcdS.BasePath)
	err = s.Serve("tcp", basics.ServeS.Port)

	if err != nil {
		panic(err.Error())
	}
}
